import { Module } from "vuex";

import { RootStateTypes, SettingsState } from "../interface/index";

const settings: Module<SettingsState, RootStateTypes> = {
	state() {
		return {
			logo: "GithubOutlined",
			title: localStorage.getItem("当前系统名称") ? localStorage.getItem("当前系统名称") : "",
			isCollapse: false,
			selectedMenu: [],
			openMenu: [],
			breadcrumbList: [],
			passwordState: false,
			user: "",
			name: "",
			usertoken: localStorage.getItem("Cusertoken") ? localStorage.getItem("Cusertoken") : "",
			router: []
		};
	},
	getters: {
		logo: state => state.logo,
		title: state => state.title,
		user: state => state.user,
		name: state => state.name,
		usertoken: state => state.usertoken
	},
	mutations: {
		SET_TITLE(state, data: string) {
			state.title = data;
		},
		changeLogin(state, user) {
			state.usertoken = user;
			localStorage.setItem("Cusertoken", user);
		}
	},
	actions: {
		toggleCollapse({ commit }) {
			commit("TOGGLE_COLLAPSE");
		}
	}
};

export default settings;
